package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.nhi.could.waste.dto.HospitalPlaceDto;
import net.zigin.nhi.could.waste.service.HospitalPlaceService;

import net.zigin.nhi.could.waste.vo.HospitalPlaceVo;
import net.zigin.nhi.could.waste.vo.JsonForResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * HospitalPlace控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: HospitalPlaceController
 * @date 2021-9-8 0:01:03
 */
@Api(tags = "暂存点管理")
@RestController
@RequestMapping("/hospitalPlace")
public class HospitalPlaceController extends BaseController {
    @Autowired
    private HospitalPlaceService hospitalPlaceService;

    /**
     * 新增编辑暂存点
     *
     * @param hospitalPlaceDto 暂存点信息
     * @return 暂存点ID
     */
    @ApiOperation("新增编辑暂存点")
    @ApiImplicitParam(name = "hospitalPlaceDto", value = "暂存点信息", required = true, dataType = "HospitalPlaceDto")
    @PostMapping("/save")
    public JsonForResult<String> sava(@RequestBody HospitalPlaceDto hospitalPlaceDto) {
        String id = hospitalPlaceService.saveOrUpdate(hospitalPlaceDto);
        return JsonForResult.<String>builder().data(id).success(true).build();
    }

    /**
     * 暂存点列表
     *
     * @param hospitalPlaceDto 暂存点信息
     * @return 暂存点列表
     */
    @ApiOperation("暂存点列表")
    @ApiImplicitParam(name = "hospitalPlaceDto", value = "暂存点信息", required = true, dataType = "HospitalPlaceDto")
    @PostMapping("/getList")
    public JsonForResult<List<HospitalPlaceVo>> getList(@RequestBody HospitalPlaceDto hospitalPlaceDto) {
        List<HospitalPlaceVo> list = hospitalPlaceService.getList(hospitalPlaceDto);
        Integer count = hospitalPlaceService.getCount(hospitalPlaceDto);
        return JsonForResult.<List<HospitalPlaceVo>>builder()
                .data(list).total(count)
                .success(true).build();
    }

    /**
     * 暂存点详情
     *
     * @param id ID
     * @return 暂存点详情
     */
    @ApiOperation("暂存点详情")
    @ApiImplicitParam(name = "id", value = "暂存点id", required = true, dataType = "String")
    @GetMapping("/getById/{id}")
    public JsonForResult<HospitalPlaceVo> getById(@PathVariable String id) {
        HospitalPlaceVo hospitalPlaceVo = hospitalPlaceService.getInfoById(id);
        return JsonForResult.<HospitalPlaceVo>builder().data(hospitalPlaceVo).success(true).build();
    }

    /**
     * 删除暂存点
     *
     * @param id ID
     * @return
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation("删除暂存点")
    @ApiImplicitParam(name = "id", value = "暂存点id", required = true, dataType = "String")
    public JsonForResult remove(@PathVariable String id) {
        hospitalPlaceService.deleteByPrimaryKey(id);
        return JsonForResult.builder().success(true).build();
    }

    /**
     * 下载二维码
     *
     * @param id       科室ID
     * @param response
     * @return
     */
    @GetMapping("/generateQrCode/{id}")
    @ApiOperation("下载二维码")
    @ApiImplicitParam(name = "id", value = "暂存点id", required = true, dataType = "String")
    public void generateQrCode(@PathVariable String id, HttpServletResponse response) {
        hospitalPlaceService.generateQrCode(id, response);
    }

    @PostMapping("/generateQrCode")
    @ApiOperation("批量下载二维码")
    @ApiImplicitParam(name = "ids", value = "暂存点id列表", required = true, allowMultiple = true, dataType = "String")
    public void generateQrCode(@RequestBody List<String> ids, HttpServletResponse response) {
        hospitalPlaceService.generateQrCode(ids, response);
    }


}
